<?php

include_once('include/header.php');
require('conf/configuration.php');
include_once('class/class.MailEngine.php');
include_once('class/class.Validation.php');
include_once('class/class.Contacto.php');

if (isset($_POST['action']) && $_POST['action'] == "send") {

	$contacto = new Contacto();
	$contacto->nombre = $_POST['nombre'];
	$contacto->email = $_POST['email'];
	$contacto->telefono = $_POST['telefono'];
	$contacto->mensaje = $_POST['ref']."<BR>".$_POST['mensaje'];
	
	$result = false;
	if ($contacto->validate()) {
		$result = $contacto->submit();
		
		if ($result){
			$smarty->assign("messageOk", "Mensaje enviado.");
		}
		else{
			$smarty->assign("messageError", "Error al enviar");
			
		}
	}
	else{
		$smarty->assign("messageError", "Error en los datos");
	}
	$smarty->assign("contacto", $contacto);
	
}
$smarty->assign('ref', $_GET['ref']);
$smarty->assign('page','contacto');
$smarty->display('contacto.tpl');
